package bat.iog.hytool.pattern.behavioral.observer.demo01;

// 被监听对象
public class Thief {

    private ThiefListener listener;
    private EatListener eatlistener;

    public void registerListener(ThiefListener listener) {
        this.listener = listener;
    }
    public void registereatListener(EatListener eatlistener) {
        this.eatlistener= eatlistener;
    }
    
    public void steal() {
        // 偷之前，告诉警察
        if (listener != null) {
            Event event = new Event(this);
            // 喂，有胆开枪啊！
            listener.shot(event);
        }
        // 偷东西
        System.out.println("to steal money...");
    }

    public void eat() {
        if (eatlistener != null) {
            Event event = new Event(this);
            eatlistener.makefood(event);
        }

        System.out.println("to eat food...");
    }

}
